#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution2 {
public:
    int singleNumber(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());

        int index = 0;
        while (index < nums.size() - 1)
        {
            if (nums[index] != nums[index + 1] || nums[index + 1] != nums[index + 2])
            {
                return nums[index] == nums[index + 1] ? nums[index + 2] : nums[index];
            }
            index += 3;
        }

        return nums[index];
    }
};

class Solution3 {
public:
    vector<int> singleNumber(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        vector<int> ret;
        size_t i = 0;
        for (; i < nums.size() - 1; i += 2)
        {
            int num = nums[i] ^ nums[i + 1];
            if (num != 0)
            {
                if (i + 2 < nums.size() - 1 && nums[i + 2] == nums[i + 1])
                {
                    ret.push_back(nums[i]);
                    i = i + 1;
                    continue;
                }
                ret = { nums[i],nums[i + 1] };
                break;
            }
        }
        if (i == nums.size() - 1)
        {
            ret.push_back(nums[i]);
        }

        return ret;
    }
};

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        vector<int> v;
        for (size_t i = 0; i < nums.size() - 1; i++)
        {
            if (nums[i] != nums[i + 1])
            {
                v.push_back(nums[i]);
            }
        }

        v.push_back(nums[nums.size() - 1]);
        int k = v.size();
        for (size_t i = 0; i < k; i++)
        {
            nums[i] = v[i];
        }

        return k;
    }
};

int main()
{
    vector<int> v = { 1,1,2,3,3,5,5,9,10,11,11 };
    ////cout << Solution().singleNumber(v) << endl;
    //auto ret = Solution().singleNumber(v);
    //for (auto e : ret)
    //{
    //    cout << e << " ";
    //}
    //cout << endl;
    cout << Solution().removeDuplicates(v) << endl;

	return 0;
}